package com.the_ring.chapter09.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.the_ring.chapter09.fragment.GoodsFragment;

public class ClassifyPagerAdapter extends FragmentStateAdapter {

    private Context context;

    private Fragment applianceFragment, costumeFragment;

    public ClassifyPagerAdapter(@NonNull Fragment fragment, Context context) {
        super(fragment);
        this.context = context;
        applianceFragment = GoodsFragment.newInstance(context, GoodsFragment.APPLIANCE);
        costumeFragment = GoodsFragment.newInstance(context, GoodsFragment.COSTUME);
    }


    @NonNull
    @Override
    public Fragment createFragment(int position) {
        Log.i("ClassifyPageAdapter", "position: " + position);
        if (position == GoodsFragment.APPLIANCE) {
            return applianceFragment;
        } else if (position == GoodsFragment.COSTUME) {
            return costumeFragment;
        }
        return null;
    }

    @Override
    public int getItemCount() {
        return 2;
    }
}
